import axios from "axios";
import {
    URL_FRIEND_LINK,
    URL_FRIEND_LINK_ALL,
    URL_FRIEND_LINK_DELETE,
    URL_FRIEND_LINK_GET_STATION_TITLE
} from "@/constants/FriendLinkApiUrl";
import Page from "@/domain/Page";
import Pageable, {pageable2RequestParameters} from "@/domain/Pageable";
import FriendLink from "@/domain/FriendLink";
import {MyAxiosRequestConfig} from "@/config/config-axios";

export default class FriendLinkService{
    static async page(keywords: string, page: Pageable): Promise<Page<FriendLink>>{
        return await axios.get(URL_FRIEND_LINK, {
            params: {
                keywords,
                ...pageable2RequestParameters(page)
            }
        });
    }

    static async getAllList(): Promise<Array<FriendLink>>{
        return await axios.get(URL_FRIEND_LINK_ALL);
    }

    static async add(friendLink: FriendLink): Promise<FriendLink>{
        return await axios.post(URL_FRIEND_LINK, friendLink);
    }

    static async update(friendLink: FriendLink): Promise<FriendLink>{
        return await axios.put(URL_FRIEND_LINK, friendLink);
    }

    static async remove(id: number): Promise<void>{
        await axios.delete(URL_FRIEND_LINK_DELETE, {
            pathVariables: {id}
        } as MyAxiosRequestConfig)
    }

    static async getStationTitle(url: string): Promise<string>{
        return await axios.get(URL_FRIEND_LINK_GET_STATION_TITLE, {
            params: {url}
        });
    }
}
